package com.bdqn.service.impl;

import com.bdqn.mapper.SysUserMapper;
import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {
    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser getAccount(String account, String password) {
        return sysUserMapper.getAccount(account,password);
    }

    @Override
    public SysUser getAccountExist(String account) {
        return sysUserMapper.getAccountA(account);
    }

    @Override
    public int getCount() {
        return sysUserMapper.getCount();
    }
    @Override
    public List<SysUser> getUserList(int pageIndex, int pageSize,String queryRealName,Integer queryRoleId) {
        return sysUserMapper.getUserList(pageIndex,pageSize,queryRealName,queryRoleId);
    }

    @Override
    public int getPwd(String oldPassword, String account) {
            return sysUserMapper.getPwd(oldPassword,account);
        }

    @Override
    public SysUser getSysUser(Integer id) {
        return sysUserMapper.getSysUser(id);
    }

    @Override
    public int add(SysUser sysUserAdd) {
        return sysUserMapper.add(sysUserAdd);
    }


    @Override
    public int savePassword(String account, String pwd) {
        return sysUserMapper.savePassword(account, pwd);
    }


    @Override
    public int del(Integer id) {
        return sysUserMapper.del(id);
    }

    @Override
    public int getAccountC(String account) {
        return sysUserMapper.getAccountC(account);
    }

    @Override
    public SysUser login(String account, String password) throws Exception {
        SysUser sysUser=null;
        sysUser=sysUserMapper.getAccount(account,password);
        //匹配密码
        if(null!=sysUser){
            if(sysUser.getPassword().equals(password)){
                sysUser=null;
            }
        }
        return sysUser;
    }
}
